package cn.water.rocketmq.consumer;

import cn.water.rocketmq.service.HelloService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
@RocketMQMessageListener(topic = "producer-test-topic",consumerGroup = "consumer-group",selectorExpression = "*")
public class MyConsumer1 implements RocketMQListener<String> {
    @Autowired
    private HelloService helloService;
    @Override
    public void onMessage(String name) {
        try{
            System.out.println("拿到消息数据:"+name);
            String s = helloService.sayHi(name);
            System.out.println(s);
        }catch (RuntimeException e){
            //做日志记录
            e.printStackTrace();
        }
    }
}
